<?php

include_once("ID3Mapper.class.php");
include_once("playlistMapper.class.php");

if (isset($_POST['delete_song'])) {
    $id3 = ID3Mapper::findById($_POST['delete_song']);
    unlink("./Musica/".$id3->get_file_name());
    $id3mapper = new ID3Mapper();
    $id3mapper->delete($id3);
    
    $playlists = playlistMapper::findAllPlaylists();
    if ($playlists) {
        foreach ($playlists as $playlist) {
            $playlist->delete_song($_POST['delete_song']);
        }
    }
}

?>
